package com.gitee.wsl.model.process.request

import com.gitee.wsl.model.OutgoingContent
import com.gitee.wsl.prop.AttributeKey
import com.gitee.wsl.reflect.TypeInfo
import com.gitee.wsl.reflect.typeInfo

internal val BodyTypeAttributeKey: AttributeKey<TypeInfo> = AttributeKey("BodyTypeAttributeKey")

inline fun <reified T> ProcessRequestBuilder.setBody(body: T) {
    when (body) {
        null -> {
            this.body = NullBody
            bodyType = typeInfo<T>()
        }
        is OutgoingContent -> {
            this.body = body
            bodyType = null
        }
        else -> {
            this.body = body
            bodyType = typeInfo<T>()
        }
    }
}


fun ProcessRequestBuilder.setBody(body: Any?, bodyType: TypeInfo) {
    this.body = body ?: NullBody
    this.bodyType = bodyType
}
